home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_geomview.idb / usr / freeware / lib / geomview / doc / oogltour.z / oogltour
Encoding:
Text File  |  1999-01-26  |  18.7 KB  |  543 lines

  1. Tutorial: The OOGL Geom File Formats 
  2.         (and Geomview along the way)
  3.  
  4. OOGL stands for Object Oriented Graphics Library.  An OOGL object is
  5. called a Geom. There is a text file format for each kind of Geom. You
  6. can load a text file into any program that uses OOGL. Geomview is an
  7. interactive 3D object viewer built on top of OOGL. (Geomview runs on
  8. Silicon Graphics, NextStep, and X-Windows platforms.) There are
  9. Geomview notes in brackets interspersed throughout this guide telling
  10. you what to do in Geomview to see what we're talking about. Later
  11. notes assume you both know how to do and have done what previous notes
  12. told you about. All of the files referred to in this document are in
  13. the directory of sample OOGL files that comes with Geomview.
  14.  
  15. The OOGL File Formats section of the Geomview manual is a complete
  16. reference for the syntax of file formats. This tutorial is an attempt
  17. to lead you more gently into the world of OOGL.
  18.  
  19. ----------------------------------------------------------------------
  20. ----------------------------------------------------------------------
  21.  
  22.                 QUAD
  23.  
  24. We start with a very simple object: a square. Specifically, the unit
  25. square in the xy plane at z=0.
  26. ----------------------------------------------------------------------
  27. "square.quad":
  28.  
  29. QUAD
  30. -1 -1 0 
  31. 1 -1 0
  32. 1 1 0
  33. -1 1 0
  34. ----------------------------------------------------------------------
  35. The header "QUAD" identifies the file type.  (You can also use the
  36. header "POLY" for this type for historical reasons.)  A QUAD file is a
  37. list of 4*n vertices where n is the number of quadrilaterals. This
  38. file only contains one quadrilateral.  You can also use this format to
  39. specify triangles: just use a degenerate quadrilateral where two of
  40. the four vertices are identical.  The vertices in this file are
  41. simple: just the x,y, and z coordinates of the point.
  42.  
  43. [GEOMVIEW: Type "geomview square.quad" from a shell window on a
  44. Silicon Graphics Iris. Spin the square around with the left mouse
  45. after geomview loads it. Feel free to play with geomview a while if
  46. the fancy strikes you during this tutorial.  ]
  47.  
  48. The next file has more complex vertices that include a color with a point. 
  49. ----------------------------------------------------------------------
  50. "csquare.quad":
  51.  
  52. CQUAD
  53. -1 -1 0        1 0 0 1
  54. 1 -1 0        0 1 0 1
  55. 1 1 0        0 1 0 1
  56. -1 1 0        1 0 0 1
  57. ----------------------------------------------------------------------
  58.  
  59. It's got the same points as the previous square, but with two red and
  60. two green corners. The header is now "CQUAD" to indicate that its
  61. vertices contain color information as well as point information.
  62. Colors are specified by (r,g,b,a) 4-tuples of floating point numbers
  63. between 0 and 1. Any color that can be displayed on a computer screen
  64. can be encoded by some combination of red, green and blue. The fourth
  65. component, alpha, represents opacity: 0 is transparent and 1 is
  66. opaque. The X, NextStep, and some SGI platforms ignore alpha
  67. information entirely, but a Renderman snapshot will use the alpha
  68. information if transparency is enabled. Some SGI platforms use the
  69. alpha information, but the picture is guaranteed to be incorrect.
  70.  
  71.  
  72. [geomview: Delete the current object by hitting the Delete button.  To
  73. load csquare.quad, hit the Load Button and type "csquare.quad" (hit
  74. RETURN when you're done typing) into the popup box that appears. (If
  75. you're browsing and are not sure about file names, you can use the
  76. File Browser Button to look around in a directory.)
  77.  
  78. You're probably wondering why it's all one color.  The default shading
  79. mode is flat shading, where each polygon or polygonal face is the same
  80. color. The other two shading modes, constant and smooth, will both
  81. display multicolored faces where the colors smoothly interpolated
  82. between vertices. Constant shading ignores all lighting information,
  83. while smooth shading interpolates lighting as well as coloring between
  84. the vertices.
  85.  
  86. To change shading mode, first open up the Appearance panel by clicking
  87. on the Appearance line in the More Panels browser.  Now switch from
  88. mode to mode by clicking on different lines in the Shading browser.
  89. ]
  90.  
  91.  
  92. Time to move on to bigger and better things. 
  93.  
  94. "dodec.quad":
  95.  
  96. QUAD
  97. 0 0 0.794654 0 0.491123 0.794654 0.356822 0.491123 0.794654 0.467086 0.151765 0.794654
  98. 0 0 0.794654 -0.467086 0.151765 0.794654 -0.356822 0.491123 0.794654 4.89153e-09 0.491123 0.794654
  99. 0 0 0.794654 -0.288675 -0.397327 0.794654 -0.57735 -0.187593 0.794654 -0.467086 0.151766 0.794654
  100. 0 0 0.794654 0.288675 -0.397327 0.794654 4.36694e-09 -0.607062 0.794654 -0.288675 -0.397327 0.794654
  101. 0 0 0.794654 0.467086 0.151766 0.794654 0.57735 -0.187592 0.794654 0.288675 -0.397327 0.794654
  102. 0 0.710761 0.35538 0 0.491123 0.794654 -0.356822 0.491123 0.794654 -0.467086 0.642889 0.491123
  103.     .
  104.     .
  105.     .
  106.  < 55 lines of numbers deleted>
  107.  
  108.  
  109. Now we've got a more interesting object: a dodecahedron.  Since
  110. dodecahedra have 5-sided faces, each of its 12 faces is actually made out
  111. of 5 quadrilaterals for a total of 20 quadrilaterals in this Quad object.
  112.  
  113. [geomview: 
  114. Delete the square and load "dodec.quad". Since the 5
  115. quadilaterals on each face all fit together perfectly, the fact that
  116. there are indeed many of them on each face is only apparent when the
  117. edges are drawn. To turn on edge drawing, hit the Edges button on
  118. the Appearance panel.
  119. ]
  120.  
  121.  
  122.                 OFF
  123.  
  124. There is a much more efficient way of representing a dodecahedron.
  125.  
  126. "dodec.off":
  127.  
  128. OFF
  129. 20 12 30
  130.     1.214124 0.000000 1.589309
  131.     0.375185 1.154701 1.589309
  132.     -0.982247 0.713644 1.589309
  133.     -0.982247 -0.713644 1.589309
  134.     0.375185 -1.154701 1.589309
  135.     1.964494 0.000000 0.375185
  136.     0.607062 1.868345 0.375185
  137.     -1.589309 1.154701 0.375185
  138.     -1.589309 -1.154701 0.375185
  139.     0.607062 -1.868345 0.375185
  140.     1.589309 1.154701 -0.375185
  141.     -0.607062 1.868345 -0.375185
  142.     -1.964494 0.000000 -0.375185
  143.     -0.607062 -1.868345 -0.375185
  144.     1.589309 -1.154701 -0.375185
  145.     0.982247 0.713644 -1.589309
  146.     -0.375185 1.154701 -1.589309
  147.     -1.214124 0.000000 -1.589309
  148.     -0.375185 -1.154701 -1.589309
  149.     0.982247 -0.713644 -1.589309
  150.     5 0 1 2 3 4
  151.     5 0 5 10 6 1
  152.     5 1 6 11 7 2
  153.     5 2 7 12 8 3
  154.     5 3 8 13 9 4
  155.     5 4 9 14 5 0
  156.     5 15 10 5 14 19
  157.     5 16 11 6 10 15
  158.     5 17 12 7 11 16
  159.     5 18 13 8 12 17
  160.     5 19 14 9 13 18
  161.     5 19 18 17 16 15
  162.  
  163. The "OFF" header tells us it's a polylist file. The second line in
  164. the file tells us that there are 20 vertices, 12 faces, and 30 edges.
  165. (The OOGL libraries presently don't use the edges value, so you can
  166. just use 0 if you don't happen know the number of edges.)  The next 20
  167. lines give a list of vertices. The last 12 lines specify the faces:
  168. the first number is the number of vertices in that face. Since our
  169. polyhedron happens to be regular, all faces have the same number of
  170. vertices (in this case, 5).  The rest of the numbers on the line are
  171. indices into the above list of vertices.
  172.  
  173. Besides being far more compact, the Polylist file format embeds
  174. connectivity information in the Geom.  OOGL has no way of knowing
  175. whether any two quadrilaterals in a Quad object are connected.  But
  176. with a Polylist, OOGL can interpolate normals across connected faces.
  177. The normals of an object are used to calculate shading information.
  178. Interpolated normals make an object look smooth instead of faceted.
  179. This is often desirable if you are trying to approximate a curved
  180. surface by breaking it up into small pieces.
  181.  
  182. [geomview: 
  183. Go ahead and load "dodec.off" without deleting the other one.  Now
  184. you've got two Geoms in your world.  Most actions apply to the
  185. currently picked object. When you start up geomview, the currently
  186. picked object is the whole world. You can independently control any
  187. object in the world by picking it as the target of your actions.
  188. Double-clicking the right mouse button when the mouse is over an
  189. object picks it: double-clicking the right mouse over empty space
  190. picks the whole world. You can also pick objects by clicking on the
  191. appropriate line in the Object browser.
  192.  
  193. The two dodecahedra are probably superimposed.  Pick one of them as
  194. your target, click on the "Translate" line in the motion browser, and
  195. move the picked object away from the center of the world with the left
  196. mouse.  (To return to "Rotate" mode, click the appropriate line in the
  197. motion browser.)
  198.  
  199. Now pick the whole world again and draw the normals by hitting the
  200. "Normals" button on the Appearance panel. Switch between Flat and
  201. Smooth Shading modes (by clicking in the Shading browser) and notice
  202. that the Polylist changes but the Quad doesn't.  
  203.  
  204. Sometimes using the mouse to click on browser lines and buttons is
  205. cumbersome. The bracketed characters shown on the control panels are
  206. keyboard shortcuts that duplicate the effect of using the mouse to
  207. click on that line or button. For instance, "an" (the "a" stands for
  208. "appearance") toggles drawing normals and "t" switches the motion to
  209. translation.  In a further shortcut, you can use the prefix of an
  210. object ("g" or "c" followed by a number, as shown in brackets in the
  211. Object browser) before most commands to simultaneously pick an object
  212. and do some action to it. For instance, "g0r" lets you immediately
  213. rotate the world.
  214.  
  215. ]
  216.  
  217.  
  218. Let's compare two ways of coloring a Polylist.
  219.  
  220. facecube.off:
  221.  
  222. # off file with per face color
  223. OFF
  224. 8 6 12
  225.      1.0 1.0 1.0 
  226.      1.0 1.0 -1.0 
  227.      1.0 -1.0 1.0 
  228.      1.0 -1.0 -1.0 
  229.      -1.0 1.0 1.0 
  230.      -1.0 1.0 -1.0 
  231.      -1.0 -1.0 1.0 
  232.      -1.0 -1.0 -1.0 
  233.      4 0 2 3 1  .05 .8 .1 .75
  234.      4 4 5 7 6  .2 .05 .8 .75
  235.      4 0 4 6 2  .9 .9 .02 .75
  236.      4 1 3 7 5  .0 .7 .4 .75
  237.      4 0 1 5 4  .1 .4 .7 .75
  238.      4 2 6 7 3  .7 .7 0 .75
  239.  
  240. vertcube.off:
  241.  
  242. # off file with per vertex colors
  243. COFF
  244. 8 6 12
  245.      1.0 1.0 1.0     .05 .8 .1 .75
  246.      1.0 1.0 -1.0    .2 .05 .8 .75 
  247.      1.0 -1.0 1.0    .9 .9 .02 .75 
  248.      1.0 -1.0 -1.0     .0 .7 .4 .75
  249.      -1.0 1.0 1.0     .1 .4 .7 .75
  250.      -1.0 1.0 -1.0     .7 .7 0 .75
  251.      -1.0 -1.0 1.0     0. 0. 0. .75
  252.      -1.0 -1.0 -1.0     1. 1. 1. .75    
  253.      4 0 2 3 1  
  254.      4 4 5 7 6  
  255.      4 0 4 6 2  
  256.      4 1 3 7 5  
  257.      4 0 1 5 4  
  258.      4 2 6 7 3  
  259.  
  260. Everything following a "#" is a comment for humans to read and is
  261. ignored by OOGL. The header for a plain Polylist file is optional, but
  262. if you have anything besides points in a vertex you do need a proper
  263. header.  The object is the unit cube, which has 8 vertices, 6 faces,
  264. and 12 edges.  The first has per-face coloring and the second has
  265. per-vertex coloring.
  266.  
  267. A subtle point: the header for vertcube.off is "COFF" as you would
  268. expect but the header for facecube.off is just "OFF" because the
  269. header refers only to the structure of the vertices, not the entire
  270. file.
  271.  
  272. [geomview: 
  273. Delete everything by picking the world and hitting the Delete Object
  274. button. Now load "facecube.off" and "vertcube.off". Translate one of
  275. them away from the center so that you can see what you're doing.
  276. Switch both Polylists between Constant, Flat, and Smooth Shading
  277. modes.
  278.  
  279. Shading is done according to light sources that you have control over.
  280. To play with the lights, open the Light panel by clicking on the Light
  281. line in the More Panels browser. When you hit the Show Lights button,
  282. you will see light beams that you can drag around to move the lights.
  283. You can also add, delete, change the intensity of, and change the
  284. color of lights.
  285. ]
  286.  
  287.  
  288.                 MESH
  289.  
  290. The vertices of a Mesh file are connected in a rectangular grid.
  291.  
  292. tent.mesh:
  293. CMESH
  294. 3 3
  295. 0 0 0  1 0 0 1       1 0 1  0 1 0 1        2 0 0  0 0 1 1
  296. 0 1 0  1 0 0 1       1 1 1  0 1 0 1        2 1 0  0 0 1 1
  297. 0 2 0  1 0 0 1       1 2 1  0 1 0 1        2 2 0  0 0 1 1
  298.  
  299. The "CMESH" header tells us that this is a Mesh file and each vertex
  300. contains both point and color information.  The second line means that
  301. both the u and v dimensions of the mesh are 3, so there will be 3*3 =
  302. 9 vertices. Each vertex that's not on an outer edge is connected to
  303. its 4 surrounding neighbots by an edge. In "tent.mesh", only the
  304. point (1,1,1) is an inside point. The 9 vertices, when named (u,v),
  305. are specified in v-major order, just like an array in C:
  306.  
  307. (0,0)---(1,0)---(2,0)   
  308.   |      |      |
  309. (0,1)---(1,1)---(2,1)
  310.   |      |      |
  311. (0,2}---(1,2)---(2,2)
  312.  
  313. [geomview:
  314. Delete everything and load "tent.mesh". Go into Smooth Shading mode to
  315. see each vertex with its own color so that it's obvious how the points in
  316. the file correspond with the image in the viewer.
  317. ]
  318.  
  319. If you want the mesh to be closed along either (or both) of the u or v
  320. edges, insert either a "u" or "v" in the header just before the
  321. "MESH".
  322.     
  323. "wraptent.mesh" 
  324. CuMESH
  325. 3 3
  326. 0 0 0  1 0 0 1       1 0 1  0 1 0 1        2 0 0  0 0 1 1
  327. 0 1 0  1 0 0 1       1 1 1  0 1 0 1        2 1 0  0 0 1 1
  328. 0 2 0  1 0 0 1       1 2 1  0 1 0 1        2 2 0  0 0 1 1
  329.  
  330. [geomview: 
  331. Load "wraptent.mesh" and compare the two Meshes, translating them
  332. apart from each other as necessary.
  333. ]
  334.  
  335. There's an extremely efficient way to describe a mesh when the x and y
  336. coordinates match the u and v coordinates of every point.
  337.  
  338. "ztent.mesh":
  339. ZMESH
  340. 3 3
  341. 0 1 0
  342. 0 1 0
  343. 0 1 0
  344.  
  345. "ztent.mesh" is exactly the same shape as "tent.mesh", although its
  346. vertices don't have any colors. The header "ZMESH" means that only
  347. the z-coordinate of each point is specified and the x and y
  348. coordinates of each point are set equal to its (u,v) position in the
  349. grid.
  350.  
  351. [geomview:
  352. Load "ztent.mesh" to verify that it's really the same shape as "tent.mesh"
  353. ]
  354.  
  355.  
  356.  
  357.                 VECT
  358.  
  359. A Vect is a collection of polylines, which are lines with 1 or more
  360. vertices. Here's a file specifying an "X" and the x-axis in red, a "Y"
  361. and the y-axis in green, and a "Z" and the z-axis in blue.
  362.  
  363. "xyz.vect":
  364. VECT
  365. 8 19 3
  366. 2 2 2 2 2 3 2 4 
  367. 1 0 0 1 0 0 1 0
  368.  
  369. 0 0 0  1 0 0
  370. 1 -.05 .05   1  .05 .25
  371. 1  .05 .05   1 -.05 .25
  372.  
  373. 0 0 0  0 1 0
  374. -.05 1 .25   0  1   .15
  375.  .05 1 .25   0  1   .15   0  1  .05
  376.  
  377. 0 0 0  0 0 1
  378. -.05 .25 1  .05 .25 1   -.05 .05 1   .05  .05  1
  379.  
  380. 1 0 0 1
  381. 0 1 0 1
  382. 0 .6 1 1
  383.  
  384. The header is always "VECT": no letters can be tacked on the front.
  385. The second line means that there are 8 polylines, which have a total
  386. of 19 vertices and 3 colors. There is no indexing into a list of
  387. vertices like a polylist: every single vertex must be specified
  388. separately. The third line lists the number of vertices in each
  389. polyline. In "xyz.vect", the only polylines with more than 2 vertices
  390. are the upper part of the "Y", which has 3, and the "Z", which has 4.
  391. The fourth line lists the number of colors in each polyline.  When a
  392. polyline has no colors it inherits the previously set color.  Next
  393. come the 19 vertices: only points are allowed. Finally, the 3 colors
  394. are given on the last three lines.
  395.  
  396. [geomview: 
  397. Delete everything, load and look at "xyz.vect". Do the same thing for
  398. all the remaining examples.
  399. ]
  400.  
  401.                 BEZ
  402.  
  403. For those who already understand how to create parametric surface
  404. patches, the syntax of Bezier surface patches is described in the OOGL
  405. man page. The art of constructing parametric surfaces is not easily
  406. explained: thus, it is beyond the scope of this tutorial to discuss
  407. them.
  408.  
  409.  
  410. Lists and Insts are complex Geoms that can be used to create a
  411. hierarchical tree of objects. 
  412.  
  413.                 LIST
  414.  
  415. A List is just a collection of other Geoms.
  416.  
  417. "ref.list":
  418. LIST
  419. < xyz.vect
  420. < dodec.quad
  421. { = QUAD -1 -1 0   1 -1 0  1 1 0  -1 1 0}
  422.  
  423.  
  424. The header is always exactly "LIST". The first two subgeoms refer to
  425. other files, using the syntax " < filename ". We have omitted the
  426. optional surrounding braces.  The third is a literal, or in-line,
  427. object. Although this particular syntax would still work if we left
  428. off the surrounding braces and equal sign, very similar syntax would
  429. not so we follow the "when in doubt, use braces" rule.
  430.  
  431. [geomview:
  432. Geomview looks for filenames in the current directory, the pathname in
  433. the GEOMDATA environment variable, and the same directory as the file
  434. that it's currently reading. 
  435. ]
  436.  
  437.                 INST
  438.  
  439. An Inst is one or more 4x4 transforms applied to another Geom.  These
  440. matrices can represent all of the 3D transformations such as rotation,
  441. translation, scaling, shearing and perspective.  We use 4x4 matrices
  442. instead of 3x3 matrices so that we can use homogenous coordinates and
  443. concatenate all transformations without treating translations as
  444. special cases that require adding instead of multiplying.  4x4
  445. matrices can also be used for such operations such as 4D rotation or
  446. projective hyperbolic transformations. A linear algebra or computer
  447. graphics textbook is a good place to start if you are unfamiliar with
  448. these ideas.
  449.  
  450. "ref.inst":
  451. INST
  452. geom { < ref.list }
  453. transforms { = 
  454. TLIST
  455.  1 0 0 0
  456.  0 1 0 0
  457.  0 0 1 0
  458.  2 0 0 1
  459.  
  460.  1 0 0 0
  461.  0 1 0 0
  462.  0 0 1 0
  463.  0 2 0 1
  464.  
  465.  1 0 0 0
  466.  0 1 0 0
  467.  0 0 1 0
  468.  0 0 2 1
  469.  
  470.  1 0 0 0
  471.  0 1 0 0
  472.  0 0 1 0
  473.  0 0 0 1
  474. }
  475.  
  476. The header is always exactly "INST". The value following the "geom"
  477. keyword is a filename reference to "ref.list", which is the List we
  478. saw above.  It could also be an in-line Geom or a handle. We surround
  479. the value with braces to avoid ambiguity.
  480.  
  481. The value of the "transforms" keyword is an in-line TList. It could
  482. also be a filename reference or a handle. (See the OOGL File Formats
  483. section of the Geomview manual for specifics.) A TList is actually a
  484. full-fledged Geom, but we don't ever load a file like "foo.tlist" into
  485. the viewer because TLists are just a collection of transforms with no
  486. associated subgeom, so there's nothing to see.
  487.  
  488. A transform is exactly 16 numbers. The first three are a translations:
  489. 2 units in the x, y and z directions, respectively. The last is just
  490. the identity. The length of the TList is the number of instantiations
  491. of the unit: in this case, 4.
  492.  
  493. If we could not use instantiation, we would have had to compute 4
  494. entirely new Geoms, since the actual points in space of an object are
  495. different if you move it. Since the unit of an Inst can be another
  496. Inst, you can build up a complex hierarchy. For instance, to build a
  497. solar system you only need to generate one sphere. All the planets can be
  498. scaled and translated instantiations of that single Geom.
  499.  
  500.  
  501. "warp.inst":
  502. INST
  503. transform {
  504.         1 0 0 0
  505.         0 9 0 0
  506.         0 0 3 0
  507.         0 0 0 1
  508. }
  509. geom { < dodec.off }
  510.  
  511. This Inst has a single transform instead of a list of them. Thus we
  512. use the keyword "transform" instead of "transforms". A transform is
  513. not a Geom, so there is no header before the 16 numbers. We could also
  514. have a handle here.  (Handles are documented in the OOGL File Formats
  515. section of the Geomview manual.) Finally, we have "dodec.off" as our
  516. unit.  The order of the geom and the transform/transforms is
  517. irrelevant.
  518.  
  519.  
  520. Postscripts:
  521.  
  522. OOGL:
  523.  
  524. This tutorial doesn't document binary files or object appearances.
  525. See the OOGL File Formats section of the Geomview manual for details. 
  526.  
  527. White space in OOGL files is mostly for the benefit of human readers.
  528. "ZMESH 3 3 0 1 0 0 1 0 0 1 0" is a legal OOGL file.  The only
  529. exception is that there cannot be a line break between the last vertex
  530. index for an  OFF face and the next 4 color floats.
  531.  
  532. Geomview: 
  533.  
  534. When a Geom is loaded, it is automatically normalized to fit inside a
  535. unit cube centered around the origin. The default camera viewpoint is
  536. at {0,0,-3} looking toward the origin. To see the unaltered size and
  537. position of an object, pick the None line in the Normalization browser
  538. on the Obscure panel. In general it doesn't matter what the coordinate
  539. range of an object is as long as the entire file is consistent: {0,1},
  540. {-1,1}, {0,100}, {-1000,-500}, {17,36} are all valid ranges.
  541.  
  542.  
  543.